import mongoose from 'mongoose';
import config from '../config/config';
import utils from './utils';
let db: mongoose.Connection = mongoose.createConnection();

/* db = mongoose.createConnection(config.mongodb.localhost, { useUnifiedTopology: true, useNewUrlParser: true });
db.on('error', console.error.bind(console, 'connect error'));
db.on('open', () => {
    console.log(`${utils.getIPAdress()} Connection  ${config.mongodb.localhost} Success...`);
}) */

class mongodb {

    static connect() {
        db = mongoose.createConnection(config.mongodb.localhost, { useUnifiedTopology: true, useNewUrlParser: true });
        db.on('error', console.error.bind(console, 'connect error'));
        db.on('open', () => {
            console.log(`${utils.getIPAdress()} Connection  ${config.mongodb.localhost} Success...`);
        })
    }
}


export default mongodb;